$(function () {
    $("#member_datagrid").datagrid({
        url:'/memberInfo/selectMemberConsumeInfo.do',
        fit:true,
        fitColumns:true,
        striped:true,
        columns:[
            [
                {field:'name',title:'会员名称',align:'center',width:100},
                {field:'consumption',title:'消费金额',align:'center',width:100},
                {field:'consumeNumber',title:'充值次数',align:'center',width:100},
                {field:'chargeTotalAmount',title:'充值金额',align:'center',width:100},
            ]
        ],
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        onLoadSuccess:function (data) {
            var xData = new Array();
            var yData = new Array();
            var datas = data.rows;
            for(var i in datas){
                xData[i]=datas[i].name;
                yData[i]=datas[i].consumption;

            }
            console.log(yData);

            // 基于准备好的dom，初始化echarts图表
            var myChart = echarts.init(document.getElementById('main'));
            option = {
                color: ['#3398DB'],
                title : {
                    text: '消费报表',
                    subtext: "消费金额",
                    left : "center"//对其方式
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
                    data:['消费总额'],
                    left:"left"
                },
                toolbox: {
                    show : true,
                    feature : {
                        dataView : {show: true, readOnly: true},
                        magicType : {show: true, type: ['line', 'bar']},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'category',
                        data :xData
                    }
                ],
                yAxis : [
                    {
                        type : 'value'
                    }
                ],
                series : [

                    {
                        name:xData,
                        type:'bar',
                        data:yData,
                        markPoint : {
                            data : [
                                {type : 'max', name: '最大值'},
                                {type : 'min', name: '最小值'}
                            ]
                        },
                        markLine : {
                            data : [
                                {type : 'average', name : '平均值'}
                            ]
                        }
                    }
                ]
            };

            // 为echarts对象加载数据
            myChart.setOption(option);
        }
    });
    $.post('/memberInfo/selectData.do',function (data) {
        if(data){
            $("#consumeCount").text(data.consumeNumber);
            $("#consumeAmount").text("￥"+data.totalConsumption);
            $("#chargeAmount").text("￥"+data.chargeTotalAmount);

            $("#nameList").text(data.name);
        }
    });
})
